﻿Public Class clsTaskRecord
    Public Function save(en_task_record As entity_task_record, en_task_step_record1 As entity_task_step_record, en_task_step_record2 As entity_task_step_record) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            '更新新任务步骤状态
            szSql &= "insert into agv.task_record(sys_id,type,prod_id,status,start_time,end_time,tm,update_time,lhj,prod_spec_id) "
            szSql &= " values (?,?,?,?,?,?,?,?,?,?)"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1， en_task_record.sys_id, en_task_record.type, en_task_record.prod_id, en_task_record.status, en_task_record.start_time, en_task_record.end_time, en_task_record.tm, en_task_record.update_time, en_task_record.lhj, en_task_record.prod_spec_id)

            szSql = String.Empty
            szSql &= "insert into agv.task_step_record(sys_id,prio,pick,drop,agv,task_id,status,prod_id,update_time,lhj,prod_spec_id) "
            szSql &= " values (?,?,?,?,?,?,?,?,?,?,?)"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1， en_task_step_record1.sys_id, en_task_step_record1.prio, en_task_step_record1.pick, en_task_step_record1.drop, en_task_step_record1.agv,
                                                     en_task_step_record1.task_id, en_task_step_record1.status, en_task_step_record1.prod_id, en_task_step_record1.update_time, en_task_step_record1.lhj, en_task_step_record1.prod_spec_id)
            szSql = String.Empty
            szSql &= "insert into agv.task_step_record(sys_id,prio,pick,drop,agv,task_id,status,prod_id,previous_id,update_time,lhj,prod_spec_id) "
            szSql &= " values (?,?,?,?,?,?,?,?,?,?,?,?)"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1， en_task_step_record2.sys_id, en_task_step_record2.prio, en_task_step_record2.pick, en_task_step_record2.drop, en_task_step_record2.agv,
                                                     en_task_step_record2.task_id, en_task_step_record2.status, en_task_step_record2.prod_id, en_task_step_record2.previous_id, en_task_step_record2.update_time, en_task_step_record2.lhj, en_task_step_record2.prod_spec_id)

            szSql = String.Empty
            szSql &= "delete from agv.task where sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1， en_task_record.sys_id)

            szSql = String.Empty
            szSql &= "delete from agv.task_step where task_id = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1， en_task_record.sys_id)

            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        Finally
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function
End Class
